﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

// std headers

// qt headers
#include <QThread>

// gcmp headers

// custom headers
#include "ProjectComponentWorkflowBase.h"


namespace gmepgcs
{
    class GCS_SERVICE_EXPORTS SyncLocalProjectComponentWorkflow : public ProjectComponentWorkflowBase
    {
        Q_OBJECT

    public:
        explicit SyncLocalProjectComponentWorkflow(const ProjectComponentWorkflowArgument &argument, QObject *parent = nullptr);
        virtual ~SyncLocalProjectComponentWorkflow();

    public:
        static SyncLocalProjectComponentWorkflow *Create(const ProjectComponentWorkflowArgument &argument, QObject *parent = nullptr);

    protected:
        virtual void InternalProceed() override;

    private:
        void HandleResult(bool result, std::wstring errorMessage);

    private:
        //QThread workerThread;
    };


    class SyncWorkerThread : public QThread
    {
        Q_OBJECT

    public:
        explicit SyncWorkerThread(
            const std::wstring &projectId, 
            const std::wstring &componentId, 
            const int32_t &componentVersionInCloud,
            QObject *parent = nullptr);
        virtual ~SyncWorkerThread();

    public:
        
    signals:
        void ResultReady(bool result, std::wstring errorMessage);

    protected:
        virtual void run() override;

    private:
        std::wstring m_projectId;
        std::wstring m_componentId;
        int32_t m_componentVersionInCloud;
    };

    class SyncWorker : public QObject
    {
        Q_OBJECT

    public:
        explicit SyncWorker(QObject *parent = nullptr) ;
        virtual ~SyncWorker();

    public slots:
        void DoWork(
            const std::wstring &projectId,
            const std::wstring &componentId,
            const int32_t &componentVersionInCloud);

    signals:
        void ResultReady(bool result, std::wstring errorMessage);
    };

}